package com.example.springbootyczy.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 讲写的filter注入到spring容器当中
 */

//@Configuration
public class WebFilterConfig {

    @Bean
    public FilterRegistrationBean registrationBean1(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        //将filter对象注入
        registrationBean.setFilter(new WebFilter1());
        //设置名字
        registrationBean.setName("webFilter1");
        //过滤器顺序
        registrationBean.setOrder(1);
        //设置过滤的路径
        registrationBean.addUrlPatterns("/*");
        return  registrationBean;
    }
    @Bean
    public FilterRegistrationBean registrationBean2(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        //将filter对象注入
        registrationBean.setFilter(new WebFilter2());
        //设置名字
        registrationBean.setName("webFilter2");
        //过滤器顺序
        registrationBean.setOrder(2);
        //设置过滤的路径
        registrationBean.addUrlPatterns("/*");
        return  registrationBean;
    }
}
